package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.config.PurchaseCommonEnum;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormQuestionAnswer;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormQuestionAnswer;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormQuestionAnswerMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtWFlowFormQuestionAnswerMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormQuestionAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程表单-答疑补遗 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormQuestionAnswerServiceImpl extends ServiceImpl<WFlowFormQuestionAnswerMapper, WFlowFormQuestionAnswer> implements WFlowFormQuestionAnswerService {
    @Autowired
    private ExtWFlowFormQuestionAnswerMapper extWFlowFormQuestionAnswerMapper;
    @Override
    public RestReturnResult getQuestionAnswer(String flowId) {
        RestReturnResult<Object> hResult=RestReturnResult.error();
        EntityWrapper wrapper = new EntityWrapper<>();
        WFlowFormQuestionAnswer wFlowFormQuestionAnswer=new WFlowFormQuestionAnswer();
        wFlowFormQuestionAnswer.setFlowFormId(flowId);
        wFlowFormQuestionAnswer.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
        wrapper.setEntity(wFlowFormQuestionAnswer);
        wrapper.orderBy(" update_date ",false);
        List<WFlowFormQuestionAnswer> ls=this.selectList(wrapper);
        hResult=RestReturnResult.success();
        hResult.setData(ls);
        return hResult;
    }

    @Override
    public List<ExtWFlowFormQuestionAnswer> getExtByFormIdOrderSNum(String formId) {
        return extWFlowFormQuestionAnswerMapper.findByFormId(formId);
    }

    @Override
    public boolean setReadedQuestion(String supplierId, String formId) {
        WFlowFormQuestionAnswer wFlowFormQuestionAnswer = new WFlowFormQuestionAnswer();
        wFlowFormQuestionAnswer.setAddendumReferers(PurchaseCommonEnum.ATTACH_READED.getCode());

        WFlowFormQuestionAnswer where = new WFlowFormQuestionAnswer();
        where.setFlowFormId(formId);
        where.setSupplierId(supplierId);
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setEntity(where);
        return update(wFlowFormQuestionAnswer,entityWrapper);
    }

    @Override
    public boolean setReadedAnswer(String supplierId, String formId) {
        WFlowFormQuestionAnswer wFlowFormQuestionAnswer = new WFlowFormQuestionAnswer();
        wFlowFormQuestionAnswer.setSupplierReferers(PurchaseCommonEnum.ATTACH_READED.getCode());
        WFlowFormQuestionAnswer where = new WFlowFormQuestionAnswer();
        where.setFlowFormId(formId);
        where.setSupplierId(supplierId);
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setEntity(where);
        return update(wFlowFormQuestionAnswer,entityWrapper);

    }

}
